<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='../vue.js'></script>
</head>

<body>
    <div id='app'>
        <input type="text" v-model="search"/>
        <ul>
            <li v-for="item in newPerson" :key="item.id">
                {{item.name}}---{{item.age}}
            </li>
        </ul>
    </div>
    <script>
        Vue.config.productionTip = false;
        const vm = new Vue({
            el: '#app',
            data() {
                return {
                    search:"",
                    person:[
                     {id:"001",name:"杨幂",age:33},
                     {id:"002",name:"迪丽热巴",age:27},
                     {id:"003",name:"刘亦菲",age:30},
                     {id:"004",name:"胡歌",age:32},
                     {id:"005",name:"杨洋",age:28},
                    ],
                   
                };
            }, 
            // computed计算的意思  newPerson是相当于一个函数，也就是相当于后续我只需要通过调用这个名字就可以计算了
            // 可以通过computed计算，然后在里面写一个函数，后续想要用直接可能通过这个函数的名字来调用，到时候就会自动重新计算
            computed:{
                newPerson:function(){

                    return this.person.filter((item)=>{
                        return item.name.includes(this.search);
                    });
                },
            },
          
        });
    </script>
</body>

</html> 